/*
 * Copyright 2013 Glassy Cinema.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package hu.glassy.web.panel.account.detail;

import hu.glassy.core.model.Account;
import hu.glassy.core.service.AccountService;
import hu.glassy.web.auth.ApplicationSession;
import hu.glassy.web.page.account.edit.AccountEditPage;
import hu.glassy.web.page.account.registration.AccountActivationPage;
import hu.glassy.web.panel.common.CustomPanel;
import org.apache.wicket.Component;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.model.CompoundPropertyModel;
import org.apache.wicket.spring.injection.annot.SpringBean;

/**
 * This panel displays the data of the user
 *
 * @author molnar.alexander@sonrisa.hu
 */
public class AccountDetailPanel extends CustomPanel<Account>
{

  private static final long serialVersionUID = -220991408445278170L;

  @SpringBean
  private AccountService accountService;

  /**
   * Konstruktor
   *
   * @param id
   */
  public AccountDetailPanel(final String id)
  {
    super(id);
    setDefaultModel(new CompoundPropertyModel<Account>(ApplicationSession.get().getAccount()));

    add(new Label("active", getMainObject().isActive() ? getString("active") : getString("inactive")));
    add(new Label("name"));
    add(new Label("email"));
    add(new BookmarkablePageLink<String>("editButton", AccountEditPage.class));
    add(generateActivateButton());
  }

  private Component generateActivateButton()
  {
    final WebMarkupContainer activateLink = new BookmarkablePageLink<String>("activateButton", AccountActivationPage.class);
    activateLink.setVisible(!ApplicationSession.get().getAccount().getObject().isActive());
    activateLink.add(new Label("activateLabel", getString("account.detail.activate.link.label")));

    return activateLink;
  }
}
